<include file="default/public/header_common" />

<ul class="am-list am-list-static address-list mt-1">
  <li><img src="__ROOT__/Apps/Wap/View/default/assets/i/i-address.png" width="26" height="26" /> 收货人信息<span class="am-badge am-badge-primary am-round am-fr"><a href="{:U('Wap/Users/addressList')}?cartId={$cartId}" style="color:#fff;">选择地址</a></span></li>
  <if condition="empty($order['address'])">
  <li style="border-bottom: 1px dashed #eeeeee; text-align:center;"><a href="{:U('Wap/Users/addressList')}?cartId={$cartId}">选择地址</a></li>
  <input type="hidden" name="addressId" id="addressId" value="">
  <else />
  <li style="border-bottom: 1px dashed #eeeeee;">{$order['address']['userName']} {$order['address']['userPhone']}</li>
  <li style="border-top: 1px dashed #eeeeee;">{$order['address']['province']} {$order['address']['city']} {$order['address']['district']} {$order['address']['address']}</li>
  <input type="hidden" name="addressId" id="addressId" value="{$order['address']['addressId']} ">
  </if>
</ul>
<volist name="order['shop']" id="vo">
<div class="pro-list pro-item">
  <div class="pl-top"><!--<span class="am-fr">2015-11-16 17:21</span>-->店铺：{$vo['shopName']}</div>
  <!--<div class="pl-top"><span class="c-red am-fr">待付款</span>商品数量：12</div>-->
  <volist name="vo['goods']" id="v">
  <div class="am-g">
    <div class="am-u-sm-4 am-list-thumb"> <a href="#" class=""><div class="picauto"><img src="/{$v.goodsThumbs}" /></div></a> </div>
    <div class="am-u-sm-8 am-list-main">
      <h3 class="am-list-item-hd"><a href="{:U('Wap/Index/goodsDetail/id/' . $v['goodsId'])}" class="c-333">{$v['goodsName']}</a></h3>
      <div class="am-list-item-text"><span class="am-fr">数量：{$v['goodsNumber']}</span>合作价：<span class="c-red">¥{$v['shopPrice']}</span></div>
    </div>
  </div>
  </volist>
</div>
</volist>
<div class="wrap-box mb-1 mt-1" style="padding-bottom: 1px;">
  <ul class="am-list am-list-static address-list mb-0">
    <!--<li style="border-top: none;"><span class="am-fr">+¥{$order['postageSum']}</span>运费：</li>-->
    <li><span class="am-fr">+¥{$order['shopPriceSum']}.00</span>商品总额：</li>
    <li style="border-bottom: none;"><span class="am-fr c-red fb">+¥{$order['priceSum']}.00</span>总计：</li>
  </ul>
</div>
<div class="wrap-box mb-1" style="padding-bottom: 1px;">
  <ul class="am-list am-list-static pay-list mb-0">
    <li style="border-top: none;"><span class="c-666">购买方式</span></li>
    <li>
      <label class="am-radio am-fr" style="margin-top: 3px;">
        <input class="buywayId" type="radio" name="buywayId" value="1" data-am-ucheck>
      </label>
      直接购买<span class="c-666"></span></li>
    <li>
      <label class="am-radio am-fr" style="margin-top: 3px;">
        <input class="buywayId" type="radio" name="buywayId" value="2" data-am-ucheck data-am-modal="{target: '#doc-modal-2'}">
      </label>
      线下看货<span class="c-666"></span></li>
    <li style="border-bottom: none;">
      <label class="am-radio am-fr" style="margin-top: 3px;">
        <input class="buywayId" type="radio" name="buywayId" value="3" data-am-ucheck>
      </label>
      监管发货<span class="c-666" style="margin-left:20px;">鉴定费：¥{$order['buyway'][2]['buyConfig']['supPrice']}   运费：¥{$order['buyway'][2]['buyConfig']['postage']}</span>
      <input type="hidden" id="supPrice" name="supPrice" value="{$order['buyway'][2]['buyConfig']['supPrice']}">
      <input type="hidden" id="postage" name="postage" value="{$order['buyway'][2]['buyConfig']['postage']}">
      </li>
  </ul>
</div>
<div class="wrap-box" style="padding-bottom: 1px;">
  <ul class="am-list am-list-static pay-list mb-0">
    <li style="border-top: none;"><span class="c-666">支付方式</span></li>
    <li>
      <label class="am-radio am-fr" style="margin-top: 15px;">
        <input type="radio" name="payId" value="1" data-am-ucheck>
      </label>
      <img src="__ROOT__/Apps/Wap/View/default/assets/i/i-card.png" width="40" height="40" class="am-fl mr-1" style="margin-top: .5rem;">余额支付<br>
      <span class="f-small c-999">直接余额支付</span></li>
      <if condition="!isWeixin()">
    <li>
      <label class="am-radio am-fr" style="margin-top: 15px;">
        <input type="radio" name="payId" value="2" data-am-ucheck>
      </label>
      <img src="__ROOT__/Apps/Wap/View/default/assets/i/i-alipay.png" width="40" height="40" class="am-fl mr-1" style="margin-top: .5rem;">支付宝支付<br>
      <span class="f-small c-999">快捷便利的在线支付</span></li>
      </if>
      <if condition="isWeixin()">
      <li>
      <label class="am-radio am-fr" style="margin-top: 15px;">
        <input type="radio" name="payId" value="3" data-am-ucheck >
      </label>
      <img src="__ROOT__/Apps/Wap/View/default/assets/i/i-weixin.png" width="40" height="40" class="am-fl mr-1" style="margin-top: .5rem;">微信支付<br>
      <span class="f-small c-999">快捷便利的在线支付</span></li>
      </if>
  </ul>
</div>
<div data-am-widget="navbar" class="am-navbar am-cf navbar-bottom"	id="" style="padding: 0;">
  <ul class="am-navbar-nav am-cf am-avg-sm-2">
    <li style="text-align: left;"> 应付：<span class="c-red" id="priceSum-text">¥{$order['priceSum']}</span> </li>
    <input type="hidden" id="priceSum" name="priceSum" value="{$order['priceSum']}">
    <input type="hidden" id="storeId" name="storeId" value="">
    <li style="text-align: right;"> 
      <button type="button" class="am-btn am-btn-danger am-btn-sm" onClick="toPay()">去付款</button>
    </li>
  </ul>
</div>
<style type="text/css">
.address-form{ padding:10px 0;}
.address-form label{ text-align:left}
.store-list{ padding:10px; background:#fff; height:150px; overflow-y: auto;}
.store-list .store-radio{ clear:both;}
.store-list label{ text-align:center; margin-top:10px;}
.store-list li{ list-style:none; line-height:1.8em; text-align:left; text-indent:15px; font-size:10px;}
</style>
<div class="am-modal am-modal-no-btn" tabindex="-1" id="doc-modal-2">
  <div class="am-modal-dialog">
    <div class="am-modal-hd">
      <a href="javascript: void(0)" class="am-close am-close-spin" data-am-modal-close>&times;</a>
    </div>
    <div class="am-modal-bd">
    <span>请选择线下门店的省份地区</span>
    <div class="am-form am-form-horizontal address-form" style="background:none !important;">
    <div class="am-form-group">
      <label for="user-province" class="am-u-sm-3 am-form-label">选择省份&nbsp;</label>
      <div class="am-u-sm-9">
        <select id="areaId1" onchange='javascript:getAreaList("areaId2",this.value,0)'>
          <option value="0">请选择</option>
          <volist name="areas" id="vo">
          <option value="{$vo.areaId}" <if condition="$address['areaId1'] == $vo['areaId']">selected</if>>{$vo.areaName}</option>
          </volist>
        </select>
        <span class="am-form-caret"></span> </div>
    </div>
    <div class="am-form-group">
      <label for="user-province" class="am-u-sm-3 am-form-label">选择城市&nbsp;</label>
      <div class="am-u-sm-9">
        <select id="areaId2" onchange="javascript:getAreaList('areaId3',this.value,0)">
          <option value="0">请选择</option>
        </select>
        <span class="am-form-caret"></span> </div>
    </div>
    <div class="am-form-group">
      <label for="user-district" class="am-u-sm-3 am-form-label">选择地区&nbsp;</label>
      <div class="am-u-sm-9">
        <select id="areaId3"  onchange="javascript:getStoreList(this.value)">
          <option value="0">请选择</option>
        </select>
        <span class="am-form-caret"></span> </div>
    </div>
    
    <div>
    <div class="am-form-group store-list" id="store-list" style="display:none;">
    </div>
  </div>
    </div>
    
  </div>
</div>
<script src="__ROOT__/Apps/Wap/View/default/assets/js/jquery.min.js"></script> 
<script src="__ROOT__/Apps/Wap/View/default/assets/js/amazeui.min.js"></script>
<script src="__PUBLIC__/js/common.js"></script>
<script type="text/javascript">
$(document).ready(function() {
	var soucePriceSum = Number("{$order['priceSum']}");
	var supPrice = Number("{$order['buyway'][2]['buyConfig']['supPrice']}");
	var supPostage = Number("{$order['buyway'][2]['buyConfig']['postage']}");
	
	$(".buywayId").change(function() {
		var buywayId = $("input[name='buywayId']:checked").val();
		if(buywayId == 3) {
			$("#priceSum-text").html(soucePriceSum + supPrice + supPostage);
			$("#priceSum").val(soucePriceSum + supPrice + supPostage);
		} else if(buywayId == 3) {
			$("#priceSum-text").html(soucePriceSum);
			$("#priceSum").val(soucePriceSum);
		} else {
			$("#priceSum-text").html(soucePriceSum);
			$("#priceSum").val(soucePriceSum);
		}
		
	});
});

function getAreaList(objId,parentId,t,id){
	var params = {};
	params.parentId = parentId;
	$('#'+objId).empty();
	if(t<1){
	   $('#areaId3').empty();
	   $('#areaId3').html('<option value="">请选择</option>');
	}
	var html = [];
	$.post("{:U('Wap/Index/getAreasList')}",params,function(data,textStatus){
		html.push('<option value="">请选择</option>');
		var json = MXC.toJson(data);
		if(json.status=='1' && json.list.length>0){
			var opts = null;
			for(var i=0;i<json.list.length;i++){
				opts = json.list[i];
				html.push('<option value="'+opts.areaId+'" '+((id==opts.areaId)?'selected':'')+'>'+opts.areaName+'</option>');
			}
		}
		$('#'+objId).html(html.join(''));
	});
}

function getStoreList(areaId3) {
	var params = {};
	params.areaId3 = areaId3;
	var html = [];
	$.post("{:U('Api/Order/lineStore')}",params,function(data,textStatus){
		var json = MXC.toJson(data);
		storeCount = json.data.length;
		if(json.code=='1' && storeCount>0){
			$('#store-list').css('display','block');
			var opts = null;
			for(var i=0;i<storeCount;i++){
				opts = json.data[i];
				html.push('<div class="store-radio">	<label class="am-u-sm-1 am-form-label"><input type="radio" name="storeId" value="'+opts.storeId+'" onClick="setStoreId(this.value)"></label><div class="am-u-sm-10 mb10"><li style="border-bottom: 1px dashed #eeeeee;">'+opts.storeName+'</li><li style="border-top: 1px dashed #eeeeee;">'+opts.storeAddress+'</li><li style="border-top: 1px dashed #eeeeee;">'+opts.storeTel+'</li></div></div>');
			}
		}
		$('#store-list').html(html.join(''));
	});
}

function setStoreId(storeId) {
	$("#storeId").val(storeId);
}
function toPay() {
	var params = {};
	params.cartId = "{$cartId}";
	params.addressId = $("#addressId").val();
	params.buywayId = $("input[name='buywayId']:checked").val();
	params.payId = $("input[name='payId']:checked").val();
	params.storeId = $("#storeId").val();
	
	if(params.cartId==''){
	   alert("没有要结算的商品!");
	   return;
	}
	if(params.addressId==''){
	   alert("请选择收货地址!");
	   return;
	}
	if(typeof(params.buywayId) =='undefined'){
	   alert("请选择购买方式!");
	   return;
	}
	if(params.buywayId=='2' && params.storeId==''){
	   alert("请选择线下门店!");
	   return;
	}
	if(typeof(params.payId) =='undefined'){
	   alert("请选择支付方式!");
	   return;
	}
	
	$.post("{:U('Wap/Order/PayOrder')}",params,function(data,textStatus){
		var json = MXC.toJson(data);
		if(json.code == 1) {
			alert(json.info);
			window.location = "{:U('Wap/Order/wapToPay/')}?orderSN=" + json.data.orderSN;
		} else {
			alert(json.info);
		}
	});
}
</script>
</body>
</html>
